package pl.veneo.wigprofit.view {
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.ui.Mouse;
	
	public class CursorManager {
		
		public static const NORMAL: String = "normal";
		public static const ARROW: String = "arrow";
		private var _cursorArrow: Sprite;
		
		private static var _instance : CursorManager;
		private var _container : Sprite;

		public static function getInstance( container: Sprite = null) : CursorManager {
			
			if ( _instance == null ) _instance = new  CursorManager(container);
			return _instance;
		}

		public function CursorManager( container : Sprite ) {
			
			_container = container;
			_cursorArrow = _container.addChild(new Sprite()) as Sprite;
			_cursorArrow.graphics.lineStyle(1,0x000000);
			_cursorArrow.graphics.moveTo(-10, 0);
			_cursorArrow.graphics.lineTo(10, 0);
			_cursorArrow.graphics.moveTo(0, -10);
			_cursorArrow.graphics.lineTo(0, 10);
			_cursorArrow.visible = false;
			_cursorArrow.mouseEnabled = false;
			
		}
		
		public function switchTo( cursor: String ) : void {
			
			switch(cursor){
				case NORMAL:
				_container.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
				_cursorArrow.visible = false;
				Mouse.show();
				break;
				case ARROW:
				_container.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
				_cursorArrow.visible = true;
				Mouse.hide();
				break;
			}
			
		}
		
		private function mouseMoveHandler( ev: MouseEvent) : void {
		
			_cursorArrow.x = _container.mouseX;
			_cursorArrow.y = _container.mouseY;
			
		}

	}
}
		
		

